]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
js: Cleanup usage of StScrollView
authorZander Brown <zbrown@gnome.org>
Tue, 7 Nov 2023 10:47:14 +0000 (10:47 +0000)
committerMarge Bot <marge-bot@gnome.org>
Fri, 10 Nov 2023 20:19:13 +0000 (20:19 +0000)
Whilst you *can* use add_actor() with ScrollView, it's more idiomatic to
work on :child

Cleanup a few extras along the way

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3010>

12 files changed:
js/gdm/authList.js
js/gdm/loginDialog.js
js/ui/appDisplay.js
js/ui/calendar.js
js/ui/components/telepathyClient.js
js/ui/dateMenu.js
js/ui/dialog.js
js/ui/lookingGlass.js
js/ui/popupMenu.js
js/ui/search.js
js/ui/switcherPopup.js
js/ui/unlockDialog.js

index d46fb11bb6d6141f2813056f3bc3bb6544b9cfc5..e0351a2715dc2d6440d11c76c23f0c1706d2b572 100644 (file)
@@ -84,20 +84,19 @@ export const AuthList = GObject.registerClass({
         this.label = new St.Label({style_class: 'login-dialog-auth-list-title'});
         this.add_child(this.label);
 
-        this._scrollView = new St.ScrollView({
-            style_class: 'login-dialog-auth-list-view',
-        });
-        this._scrollView.set_policy(
-            St.PolicyType.NEVER, St.PolicyType.AUTOMATIC);
-        this.add_child(this._scrollView);
-
         this._box = new St.BoxLayout({
             vertical: true,
             style_class: 'login-dialog-auth-list',
             pseudo_class: 'expanded',
         });
 
-        this._scrollView.add_child(this._box);
+        this._scrollView = new St.ScrollView({
+            style_class: 'login-dialog-auth-list-view',
+            hscrollbar_policy: St.PolicyType.NEVER,
+            child: this._box,
+        });
+        this.add_child(this._scrollView);
+
         this._items = new Map();
 
         this.connect('key-focus-in', this._moveFocusToItems.bind(this));
@@ -129,7 +128,7 @@ export const AuthList = GObject.registerClass({
     scrollToItem(item) {
         let box = item.get_allocation_box();
 
-        let adjustment = this._scrollView.get_vscroll_bar().get_adjustment();
+        const {adjustment} = this._scrollView.vscroll;
 
         let value = (box.y1 + adjustment.step_increment / 2.0) - (adjustment.page_size / 2.0);
         adjustment.ease(value, {
index 0121a2fdc7ebfbedfd047e7a40426618ce3deaf0..f3afdbb5e0e71b867322964c401ee4e704419666 100644 (file)
@@ -168,10 +168,8 @@ const UserList = GObject.registerClass({
             style_class: 'login-dialog-user-list-view',
             x_expand: true,
             y_expand: true,
+            hscrollbar_policy: St.PolicyType.NEVER,
         });
-        this.set_policy(
-            St.PolicyType.NEVER,
-            St.PolicyType.AUTOMATIC);
 
         this._box = new St.BoxLayout({
             vertical: true,
@@ -179,7 +177,7 @@ const UserList = GObject.registerClass({
             pseudo_class: 'expanded',
         });
 
-        this.add_child(this._box);
+        this.child = this._box;
         this._items = {};
     }
 
@@ -226,7 +224,7 @@ const UserList = GObject.registerClass({
     scrollToItem(item) {
         let box = item.get_allocation_box();
 
-        let adjustment = this.get_vscroll_bar().get_adjustment();
+        const {adjustment} = this.vscroll;
 
         let value = (box.y1 + adjustment.step_increment / 2.0) - (adjustment.page_size / 2.0);
         adjustment.ease(value, {
@@ -238,7 +236,7 @@ const UserList = GObject.registerClass({
     jumpToItem(item) {
         let box = item.get_allocation_box();
 
-        let adjustment = this.get_vscroll_bar().get_adjustment();
+        const {adjustment} = this.vscroll;
 
         let value = (box.y1 + adjustment.step_increment / 2.0) - (adjustment.page_size / 2.0);
 
@@ -487,17 +485,16 @@ export const LoginDialog = GObject.registerClass({
 
         this._userSelectionBox.add_child(this._notListedButton);
 
+        const bannerBox = new St.BoxLayout({vertical: true});
+
         this._bannerView = new St.ScrollView({
             style_class: 'login-dialog-banner-view',
             opacity: 0,
-            vscrollbar_policy: St.PolicyType.AUTOMATIC,
             hscrollbar_policy: St.PolicyType.NEVER,
+            child: bannerBox,
         });
         this.add_child(this._bannerView);
 
-        let bannerBox = new St.BoxLayout({vertical: true});
-
-        this._bannerView.add_child(bannerBox);
         this._bannerLabel = new St.Label({
             style_class: 'login-dialog-banner',
             text: '',
index 901bb5516c40d82d9e948ffec6b7eba8fa12a52a..44bcd3dbf193228de815359720f8e3776f5fd216 100644 (file)
@@ -520,15 +520,15 @@ var BaseAppView = GObject.registerClass({
             y_expand: true,
             reactive: true,
             enable_mouse_scrolling: false,
+            hscrollbar_policy: St.PolicyType.EXTERNAL,
+            vscrollbar_policy: St.PolicyType.NEVER,
+            child: this._grid,
         });
-        this._scrollView.set_policy(St.PolicyType.EXTERNAL, St.PolicyType.NEVER);
 
         this._canScroll = true; // limiting scrolling speed
         this._scrollTimeoutId = 0;
         this._scrollView.connect('scroll-event', this._onScroll.bind(this));
 
-        this._scrollView.add_child(this._grid);
-
         const scroll = this._scrollView.hscroll;
         this._adjustment = scroll.adjustment;
         this._adjustment.connect('notify::value', adj => {
index 913203e043cf6f5d85a9719ccf527083b1505dca..11945a7884080ee6e2bf243d8737ea092d4e381d 100644 (file)
@@ -954,8 +954,8 @@ class CalendarMessageList extends St.Widget {
             style_class: 'vfade',
             overlay_scrollbars: true,
             x_expand: true, y_expand: true,
+            hscrollbar_policy: St.PolicyType.NEVER,
         });
-        this._scrollView.set_policy(St.PolicyType.NEVER, St.PolicyType.AUTOMATIC);
         box.add_child(this._scrollView);
 
         let hbox = new St.BoxLayout({style_class: 'message-list-controls'});
@@ -1008,7 +1008,7 @@ class CalendarMessageList extends St.Widget {
             'actor-added', this._sync.bind(this),
             'actor-removed', this._sync.bind(this),
             this);
-        this._scrollView.add_child(this._sectionList);
+        this._scrollView.child = this._sectionList;
 
         this._mediaSection = new Mpris.MediaSection();
         this._addSection(this._mediaSection);
index 001c5d274801127c6bf37e92621e41adb4687b0d..41f1be7043f3daf4b25ac786170701d95b10b95a 100644 (file)
@@ -870,17 +870,17 @@ class ChatNotificationBanner extends MessageTray.NotificationBanner {
             this.emit('unfocused');
         });
 
+        this._contentArea = new St.BoxLayout({
+            style_class: 'chat-body',
+            vertical: true,
+        });
         this._scrollArea = new St.ScrollView({
             style_class: 'chat-scrollview vfade',
             vscrollbar_policy: St.PolicyType.AUTOMATIC,
             hscrollbar_policy: St.PolicyType.NEVER,
             visible: this.expanded,
+            child: this._contentArea,
         });
-        this._contentArea = new St.BoxLayout({
-            style_class: 'chat-body',
-            vertical: true,
-        });
-        this._scrollArea.add_child(this._contentArea);
 
         this.setExpandedBody(this._scrollArea);
         this.setExpandedLines(CHAT_EXPAND_LINES);
index d9219fda2dc90d2e44d3504873b5568dfc8e1027..53134deb6c0407a73aec5dd304ce2042a2ef7b7f 100644 (file)
@@ -919,21 +919,22 @@ class DateMenuButton extends PanelMenu.Button {
         vbox.add_child(this._date);
         vbox.add_child(this._calendar);
 
+        const displaysBox = new St.BoxLayout({
+            vertical: true,
+            x_expand: true,
+            style_class: 'datemenu-displays-box',
+        });
+
         this._displaysSection = new St.ScrollView({
             style_class: 'datemenu-displays-section vfade',
             x_expand: true,
             overlay_scrollbars: true,
+            hscrollbar_policy: St.PolicyType.NEVER,
+            vscrollbar_policy: St.PolicyType.EXTERNAL,
+            child: displaysBox,
         });
-        this._displaysSection.set_policy(St.PolicyType.NEVER, St.PolicyType.EXTERNAL);
         vbox.add_child(this._displaysSection);
 
-        const displaysBox = new St.BoxLayout({
-            vertical: true,
-            x_expand: true,
-            style_class: 'datemenu-displays-box',
-        });
-        this._displaysSection.add_child(displaysBox);
-
         this._eventsItem = new EventsSection();
         displaysBox.add_child(this._eventsItem);
 
index 62602870f496a4f96b7aa080790fb82ec383de3a..f0dc021ce5b68911069eabf71d4d81dd4e27e367 100644 (file)
@@ -259,16 +259,16 @@ export const ListSection = GObject.registerClass({
     _init(params) {
         this._title = new St.Label({style_class: 'dialog-list-title'});
 
-        this._listScrollView = new St.ScrollView({
-            style_class: 'dialog-list-scrollview',
-            hscrollbar_policy: St.PolicyType.NEVER,
-        });
-
         this.list = new St.BoxLayout({
             style_class: 'dialog-list-box',
             vertical: true,
         });
-        this._listScrollView.add_child(this.list);
+
+        this._listScrollView = new St.ScrollView({
+            style_class: 'dialog-list-scrollview',
+            hscrollbar_policy: St.PolicyType.NEVER,
+            child: this.list,
+        });
 
         let defaultParams = {
             style_class: 'dialog-list',
index 83f563c7afca66438761f4446e2e251a4ad1c9c7..3a8c0be7354c9b07bd600e37c0a602afad729d90 100644 (file)
@@ -162,9 +162,8 @@ const Notebook = GObject.registerClass({
         labelBox.add_child(label);
         this.tabControls.add_child(labelBox);
 
-        let scrollview = new St.ScrollView({y_expand: true});
-        scrollview.get_hscroll_bar().hide();
-        scrollview.add_child(child);
+        const scrollview = new St.ScrollView({y_expand: true, child});
+        scrollview.hscroll.hide();
 
         const tabData = {
             child,
@@ -395,7 +394,7 @@ class ObjInspector extends St.ScrollView {
 
         this._parentList = [];
 
-        this.get_hscroll_bar().hide();
+        this.hscroll.hide();
         this._container = new St.BoxLayout({
             name: 'LookingGlassPropertyInspector',
             style_class: 'lg-dialog',
@@ -403,7 +402,7 @@ class ObjInspector extends St.ScrollView {
             x_expand: true,
             y_expand: true,
         });
-        this.add_child(this._container);
+        this.child = this._container;
 
         this._lookingGlass = lookingGlass;
     }
index 131f9ba6c65b5816472a98826acc40caf511a854..737188c136ad416ca0dbcdb97b02ec7c0a928cf7 100644 (file)
@@ -1016,9 +1016,9 @@ export class PopupSubMenu extends PopupMenuBase {
             style_class: 'popup-sub-menu',
             hscrollbar_policy: St.PolicyType.NEVER,
             vscrollbar_policy: St.PolicyType.NEVER,
+            child: this.box,
         });
 
-        this.actor.add_child(this.box);
         this.actor._delegate = this;
         this.actor.clip_to_allocation = true;
         this.actor.connect('key-press-event', this._onKeyPressEvent.bind(this));
index d31265be3942f8eb76c0796931f1dc4e6196a4ba..76918290cf5dbae4f168817598c6d483e2973188 100644 (file)
@@ -573,9 +573,9 @@ export const SearchResultsView = GObject.registerClass({
             style_class: 'search-display vfade',
             x_expand: true,
             y_expand: true,
+            hscrollbar_policy: St.PolicyType.NEVER,
+            child: this._content,
         });
-        this._scrollView.set_policy(St.PolicyType.NEVER, St.PolicyType.AUTOMATIC);
-        this._scrollView.add_child(this._content);
 
         let action = new Clutter.PanAction({interpolate: true});
         action.connect('pan', this._onPan.bind(this));
index cc44c401aa4ca023a436965f16ac0d9a523bd3f0..9017d2c9eaf0972edaba91e034bb6d1273487ac5 100644 (file)
@@ -409,10 +409,11 @@ export const SwitcherList = GObject.registerClass({
         this._scrollView = new St.ScrollView({
             style_class: 'hfade',
             enable_mouse_scrolling: false,
+            hscrollbar_policy: St.PolicyType.NEVER,
+            vscrollbar_policy: St.PolicyType.NEVER,
+            child: this._list,
         });
-        this._scrollView.set_policy(St.PolicyType.NEVER, St.PolicyType.NEVER);
 
-        this._scrollView.add_child(this._list);
         this.add_child(this._scrollView);
 
         // Those arrows indicate whether scrolling in one direction is possible
index 26092320fdcdae009a7f36ed77c7a6e52b465238..94da3270dcadcaa85709e16083d9ebf0b6000567 100644 (file)
@@ -43,13 +43,15 @@ const NotificationsBox = GObject.registerClass({
             name: 'unlockDialogNotifications',
         });
 
-        this._scrollView = new St.ScrollView({hscrollbar_policy: St.PolicyType.NEVER});
         this._notificationBox = new St.BoxLayout({
             vertical: true,
             style_class: 'unlock-dialog-notifications-container',
         });
-        this._scrollView.add_child(this._notificationBox);
 
+        this._scrollView = new St.ScrollView({
+            hscrollbar_policy: St.PolicyType.NEVER,
+            child: this._notificationBox,
+        });
         this.add_child(this._scrollView);
 
         this._settings = new Gio.Settings({